import { ElMessage, ElNotification } from 'element-plus'
import type { MessageType } from 'element-plus'

export interface MessageOptions {
  type?: MessageType
  duration?: number
  showClose?: boolean
}

// 消息提示服务
export const messageService = {
  // 成功消息
  success(message: string, options?: MessageOptions) {
    ElMessage({
      message,
      type: 'success',
      duration: options?.duration || 3000,
      showClose: options?.showClose || false,
      ...options,
    })
  },

  // 错误消息
  error(message: string, options?: MessageOptions) {
    ElMessage({
      message,
      type: 'error',
      duration: options?.duration || 3000,
      showClose: options?.showClose || true,
      ...options,
    })
  },

  // 警告消息
  warning(message: string, options?: MessageOptions) {
    ElMessage({
      message,
      type: 'warning',
      duration: options?.duration || 3000,
      showClose: options?.showClose || false,
      ...options,
    })
  },

  // 信息消息
  info(message: string, options?: MessageOptions) {
    ElMessage({
      message,
      type: 'info',
      duration: options?.duration || 3000,
      showClose: options?.showClose || false,
      ...options,
    })
  },

  // 通知消息
  notification: {
    success(title: string, message?: string) {
      ElNotification({
        title,
        message,
        type: 'success',
        duration: 4500,
      })
    },

    error(title: string, message?: string) {
      ElNotification({
        title,
        message,
        type: 'error',
        duration: 0, // 不自动关闭
      })
    },

    warning(title: string, message?: string) {
      ElNotification({
        title,
        message,
        type: 'warning',
        duration: 4500,
      })
    },

    info(title: string, message?: string) {
      ElNotification({
        title,
        message,
        type: 'info',
        duration: 4500,
      })
    },
  },
}
